home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1999 April / Cd Pc Users extra 19 abril 1999.iso / Prog / Inst / addin / Propset.cls < prev    next >
Encoding:
Text File  |  1997-05-20  |  5.2 KB  |  176 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "PropSet"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. Attribute VB_Description = "Property Setter"
  9. ' ************************************************
  10. ' This class implements the Set Properties add-in.
  11. '
  12. ' If includes the ConnectAddIn and DisconnectAddIn
  13. ' subroutines in addition to the property setting
  14. ' event handler code.
  15. ' ************************************************
  16. Option Explicit
  17.  
  18. ' The environment instance.
  19. Dim VBInstance As VBIDE.Application
  20.  
  21. ' The command line.
  22. Dim SetPropLine As VBIDE.MenuLine
  23.  
  24. ' The event connection ID. Represents the
  25. ' event handler to menu line connection.
  26. Dim SetPropID As Long
  27.  
  28. ' ************************************************
  29. ' Connect the add-in to the Visual basic
  30. ' environment. This happens when the user invokes
  31. ' the Add-in Manager to put the add-in in the
  32. ' Add-Ins menu.
  33. ' ************************************************
  34. Sub ConnectAddIn(vb_instance As VBIDE.Application)
  35.     ' Save the Visual Basic instance for later.
  36.     Set VBInstance = vb_instance
  37.     
  38.     ' Add the command.
  39.     Set SetPropLine = VBInstance.AddInMenu.MenuItems.Add("&Set Properties...")
  40.     
  41.     ' Connect the event handler object to the
  42.     ' menu line.
  43.     SetPropID = SetPropLine.ConnectEvents(Me)
  44. End Sub
  45. ' ************************************************
  46. ' Set the properties for the selected controls.
  47. ' ************************************************
  48. Public Sub AfterClick()
  49.  
  50.     ' Present the dialog.
  51.     Set SetterDialog.prop_setter = Me
  52.     SetterDialog.Show vbModal
  53.     Unload SetterDialog
  54. End Sub
  55. ' ************************************************
  56. ' Disconnect the add-in from the Visual basic
  57. ' environment. This happens when the user invokes
  58. ' the Add-in Manager to put the add-in in the
  59. ' Add-Ins menu.
  60. ' ************************************************
  61. Sub DisconnectAddIn(mode As Integer)
  62.     ' Disconnect the event handlers.
  63.     SetPropLine.DisconnectEvents SetPropID
  64.     
  65.     ' Remove the command.
  66.     VBInstance.AddInMenu.MenuItems.Remove SetPropLine
  67. End Sub
  68.  
  69.  
  70.  
  71.  
  72. ' ************************************************
  73. ' Return a list of the selected controls and their
  74. ' property values.
  75. ' ************************************************
  76. Public Function GetValues(prop_name As String) As String
  77. Dim ctl As Object
  78. Dim controls As VBIDE.SelectedControlTemplates
  79. Dim txt As String
  80. Dim value As String
  81. Dim field_name As String
  82. Dim idx As String
  83.  
  84.     GetValues = ""
  85.     If NoControls() Then Exit Function
  86.     
  87.     Set controls = VBInstance.ActiveProject. _
  88.         ActiveForm.SelectedControlTemplates
  89.     
  90.     txt = ""
  91.     For Each ctl In controls
  92.         field_name = ctl.Properties("Name")
  93.         idx = ctl.Properties("Index")
  94.         If idx <> "-1" Then _
  95.             field_name = field_name & _
  96.             "(" & idx & ")"
  97.         txt = txt & field_name & _
  98.             Space$(20 - Len(field_name))
  99.         
  100.         On Error Resume Next
  101.         value = ctl.Properties(prop_name)
  102.         If Err.Number = 438 Then
  103.             ' Property not supported.
  104.             value = ""
  105.         ElseIf Err.Number <> 0 Then
  106.             Beep
  107.             MsgBox "Error reading property." & _
  108.                 Error.Description, _
  109.                 vbOKOnly + vbInformation, _
  110.                 "Property Error"
  111.             Exit Function
  112.         End If
  113.         On Error GoTo 0
  114.         
  115.         txt = txt & value & vbCrLf
  116.     Next ctl
  117.     GetValues = txt
  118. End Function
  119. ' ************************************************
  120. ' Set the indicated property value. Return an
  121. ' updated list of the selected controls and their
  122. ' property values.
  123. ' ************************************************
  124. Public Function SetValues(prop_name As String, prop_value As String) As String
  125. Dim ctl As Object
  126. Dim controls As VBIDE.SelectedControlTemplates
  127. Dim txt As String
  128. Dim field_name As String
  129. Dim idx As String
  130.  
  131.     SetValues = ""
  132.     If NoControls() Then Exit Function
  133.     
  134.     Set controls = VBInstance.ActiveProject. _
  135.         ActiveForm.SelectedControlTemplates
  136.     
  137.     For Each ctl In controls
  138.         On Error Resume Next
  139.         ctl.Properties(prop_name) = prop_value
  140.         If Err.Number <> 0 And Err.Number <> 438 Then
  141.             Beep
  142.             MsgBox "Error setting property." & _
  143.                 Error.Description, _
  144.                 vbOKOnly + vbInformation, _
  145.                 "Property Error"
  146.             Exit Function
  147.         End If
  148.         On Error GoTo 0
  149.     Next ctl
  150.     SetValues = GetValues(prop_name)
  151. End Function
  152.  
  153.  
  154. ' ************************************************
  155. ' Return true if there are no controls selected.
  156. ' ************************************************
  157. Function NoControls() As Boolean
  158.     NoControls = True
  159.     
  160.     ' Sneak up on the collection of selected
  161.     ' controls so we don't try to access an
  162.     ' object that is Nothing.
  163.     If VBInstance.ActiveProject Is Nothing Then _
  164.         Exit Function
  165.     If VBInstance.ActiveProject.ActiveForm _
  166.         Is Nothing Then _
  167.         Exit Function
  168.     If VBInstance.ActiveProject.ActiveForm. _
  169.         SelectedControlTemplates.Count < 1 Then _
  170.         Exit Function
  171.             
  172.     NoControls = False
  173. End Function
  174.  
  175.  
  176.